/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package me.uniauto.zz.cwl.web.syrk;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import me.uniauto.zz.cwl.entity.syrk.CwlSyrkRk;
import me.uniauto.zz.cwl.service.syrk.CwlSyrkRkService;

/**
 * 人口Controller
 * @author 王宽
 * @version 2019-02-15
 */
@Controller
@RequestMapping(value = "${adminPath}/cwl/syrk/cwlSyrkRk")
public class CwlSyrkRkController extends BaseController {

	@Autowired
	private CwlSyrkRkService cwlSyrkRkService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public CwlSyrkRk get(String jmxxid, boolean isNewRecord) {
		return cwlSyrkRkService.get(jmxxid, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("cwl:syrk:cwlSyrkRk:view")
	@RequestMapping(value = {"list", ""})
	public String list(CwlSyrkRk cwlSyrkRk, Model model) {
		model.addAttribute("cwlSyrkRk", cwlSyrkRk);
		return "zz/cwl/syrk/cwlSyrkRkList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("cwl:syrk:cwlSyrkRk:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<CwlSyrkRk> listData(CwlSyrkRk cwlSyrkRk, HttpServletRequest request, HttpServletResponse response) {
		cwlSyrkRk.setPage(new Page<>(request, response));
		Page<CwlSyrkRk> page = cwlSyrkRkService.findPage(cwlSyrkRk);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("cwl:syrk:cwlSyrkRk:view")
	@RequestMapping(value = "form")
	public String form(CwlSyrkRk cwlSyrkRk, Model model) {
		model.addAttribute("cwlSyrkRk", cwlSyrkRk);
		return "zz/cwl/syrk/cwlSyrkRkForm";
	}

	/**
	 * 保存人口
	 */
	@RequiresPermissions("cwl:syrk:cwlSyrkRk:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated CwlSyrkRk cwlSyrkRk) {
		cwlSyrkRkService.save(cwlSyrkRk);
		return renderResult(Global.TRUE, text("保存人口成功！"));
	}
	
	/**
	 * 停用人口
	 */
	@RequiresPermissions("cwl:syrk:cwlSyrkRk:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(CwlSyrkRk cwlSyrkRk) {
		cwlSyrkRk.setStatus(CwlSyrkRk.STATUS_DISABLE);
		cwlSyrkRkService.updateStatus(cwlSyrkRk);
		return renderResult(Global.TRUE, text("停用人口成功"));
	}
	
	/**
	 * 启用人口
	 */
	@RequiresPermissions("cwl:syrk:cwlSyrkRk:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(CwlSyrkRk cwlSyrkRk) {
		cwlSyrkRk.setStatus(CwlSyrkRk.STATUS_NORMAL);
		cwlSyrkRkService.updateStatus(cwlSyrkRk);
		return renderResult(Global.TRUE, text("启用人口成功"));
	}
	
	/**
	 * 删除人口
	 */
	@RequiresPermissions("cwl:syrk:cwlSyrkRk:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(CwlSyrkRk cwlSyrkRk) {
		cwlSyrkRkService.delete(cwlSyrkRk);
		return renderResult(Global.TRUE, text("删除人口成功！"));
	}
	
}